<?php
namespace Home\Controller;
use Think\Controller;
class LoginController extends Controller {
    public function login(){
        $this -> display();
    }

    // 登录检测
    public function check_login() {

        $arr = I();
        $user_name = $arr['username'];
        $pass_word = $arr['password'];

        if (empty($user_name)) {
            $this -> error('帐号必须');
        } else if (empty($pass_word)) {
            $this -> error('密码必须');
        }
        $map = array();
        $map['tea_id'] = $user_name;
        $isExist = M('teacher') -> where($map) -> find();
        if (!$isExist) {
            $this -> error("账号不存在");
        } else {
            if ($isExist['tea_password'] == md5($pass_word)) {
                session(C('USER_AUTH_INFO'),$isExist);
                session(C('USER_AUTH_KEY'), $isExist['tea_id']);
                session(C('USER_AUTH_ROLE'), $isExist['tea_manager']);
                $this->success('登录成功','','Main/index');
            } else {
                $this -> error("密码错误");
            }


        }


    }
    /* 退出登录 */
    public function logout() {
        $user = session(C('USER_AUTH_KEY'));
        if (isset($user)) {
            session(null);
            redirect(U("Login/login"));
            $this -> success('退出成功！');
        } else {
            redirect(U("login/index"));
            $this -> error('退出成功！');
        }
    }

}



?>